<template>
    <el-select v-model="sltValue" class="w-full" clearable placeholder="请选择所属成员111" @focus="handleFocus"
        @change="doSelectChange">
        <el-option v-for="item in options" :key="item.saleId" :label="item.saleName" :value="item.saleId" />
    </el-select>
</template>

<script setup>
import { ref, watch, getCurrentInstance } from 'vue'
import { getDealList, getDeptList, getSalesmanList, getProductList } from '@/api/clients/signClient.ts'

const { emit, appContext: { app: { config: { globalProperties } } } } = getCurrentInstance()

const selectDeptMemberRef = ref(null)

const props = defineProps({
    deptId: {
        type: [String, Number]
    },
    value: {
        type: [String, Number]
    }
})

const sltValue = ref('')

const emits = defineEmits(['update:value', 'change'])
const options = ref([])

const handleFocus = () => {
    if (!props.deptId) {
        ElMessage.warning({
            message: '请先选择所属部门'
        })
        options.value = []
        return
    }
    getSalesmanList({
        auditStatus: 1,
        deptId: props.deptId
    }).then(res => {
        options.value = res
    })
}

const doSelectChange = () => {
    emits('update:value', sltValue.value)
    emits('change')
}

const clear = () => {
    options.value = []
    console.log(4567, options.value)
}

watch(() => props.value, (newval) => {
    sltValue.value = newval
}, {
    immediate: true
})

defineExpose({
    clear
})
</script>
<style lang="scss" scoped></style>